<template>
  <div class="sys-main-container">
    <div class="sys-right-container">
      <HeaderBar @getRoleCode="getRoleCode" />
      <div class="tab-box">
        <div class="tab-container">
          <PageTab ref="pageTab" />
        </div>
        <div class="right-operation">
          <span style="padding-right: 5px">
            <i class="el-icon-s-home" style="font-size: 18px" @click="goHome" />
          </span>
          <span style="padding-right: 5px">
            <i
              class="el-icon-delete"
              style="font-size: 16px"
              @click="removeAll"
            />
          </span>
          <span>
            <i
              class="el-icon-refresh"
              style="font-size: 16px"
              @click="refresh"
            />
          </span>
        </div>
      </div>
      <div class="content-view-container">
        <keep-alive :exclude="normalViews">
          <router-view style="min-width: 1000px" />
        </keep-alive>
      </div>
      <FooterBar />
    </div>
  </div>
</template>
<script>
//import configInfor from "../../devConfig.js";
import configInfor from "../../config.js";
import EventBus from "../utils/eventBus.js";
import {
  getAppLiCation,
  getNoHandleListCount,
  getSendYGMsg,
} from "../utils/apis/InpatientRegistration.js";
import HeaderBar from "@/layout/HeaderBar";
import FooterBar from "@/layout/FooterBar";
// import SiderBar from '@/layout/SiderBar'
import PageTab from "@/layout/PageTab";
import { getAppointmentTimeOut } from "../utils/apis/public.js";
export default {
  name: "Home",
  components: {
    HeaderBar,
    FooterBar,
    // SiderBar,
    PageTab,
  },
  data() {
    return {
      width: "180px",
      breads: [],
      openSider: true,
      notifyPromise: Promise.resolve(),
      normalViews: ["RegiStrationfilst", "PrebundledFilst"], // 不需要缓存的页面数组
      roleCode: "", // 当前用户角色代码
      timer: null,
      noter: null,
      isdo: false,
    };
  },
  watch: {
    $route: {
      handler(to) {
        if (to.path == "/InpatientRegistration") {
          this.isdo = true;
        } else {
          this.isdo = false;
        }
      },
      immediate: true,
    },
  },
  mounted() {
    // EventBus.$on("handleCloseTip", (value) => {
    // });
    // this.handleNotice("mount", this.roleCode);
    this.initWebSocket();
    this.getBedRecordList();
    // window.setInterval(function () {
    //   getSendYGMsg().then((res) => {
    //     if (res.data.code == 200) {
    //       console.log(res.data);
    //     }
    //   });
    //   // 5 * 60 *
    // }, 60 * 1000);
  },
  methods: {
    getBedRecordList() {
      getNoHandleListCount().then((res) => {
        if (res.data.code == 200) {
        }
        else
        {
          
        }
      });
    },
    initWebSocket: function () {
      if (typeof WebSocket === "undefined") {
        alert("您的浏览器不支持socket");
      } else {
        // 实例化socket
        this.socket = new WebSocket(`${configInfor.SCOKET_HOST_CWSQ}/003`);
        // 监听socket连接
        this.socket.onopen = this.open;
        // 监听socket错误信息
        this.socket.onerror = this.error;
        // 监听socket消息
        this.socket.onmessage = this.getMessage;
      }
    },
    open: function () {
      console.log("socket连接成功");
    },
    error: function () {
      console.log("连接错误");
    },
    getMessage: function (msg) {
      console.log("msg", msg.data);
      if (msg.data != 0) {
        // this.infoCount = Number(msg.data);
        this.$store.commit("setShowTip", msg.data);
      } else {
        this.$store.commit("setShowTip", 0);
      }
    },
    send: function () {
      this.socket.send(JSON.stringify({ msg: "123" }));
    },
    close: function () {
      console.log("socket已经关闭");
    },
    handleNotice(type, roleCode) {
      const h = this.$createElement;
      let param = {
        applicationBedno: "",
        createBy: "",
        createTime: "",
        isCrossNurse: "",
        isHandle: "",
        isNotice: "0",
        preid: 0,
        remark: "",
        updateBy: "",
        updateTime: "",
      };
      this.timer = setInterval(() => {
        getAppLiCation(param).then((res) => {
          if (res.data.code === 200) {
            if (res.data.data) {
              this.$notify.closeAll();
              // if (this.isdo) {
              //   this.noter = this.$notify({
              //     title: "提示",
              //     message: h("span", "有新患者需要处理,点击跳转"),
              //     duration: 0,
              //     type: "warning",
              //     position: "bottom-right",
              //   });
              // } else {
              //   this.noter = this.$notify({
              //     title: "提示",
              //     message: h(
              //       "span",
              //       {
              //         style: {
              //           cursor: "pointer",
              //         },
              //         on: {
              //           click: this.hanldeClick,
              //         },
              //       },
              //       "有新患者需要处理,点击跳转"
              //     ),
              //     duration: 0,
              //     type: "warning",
              //     position: "bottom-right",
              //   });
              // }
              this.noter = this.$notify({
                title: "提示",
                message: h(
                  "span",
                  {
                    style: {
                      cursor: "pointer",
                    },
                    on: {
                      click: this.hanldeClick,
                    },
                  },
                  "有新患者需要处理,点击跳转"
                ),
                duration: 0,
                type: "warning",
                position: "bottom-right",
              });
            }
          }
        });
      }, 5000);
    },
    hanldeClick() {
      if (!this.isdo) {
        this.$router.push({
          path: "/InpatientRegistration",
          query: {
            type: 1,
          },
        });
      }
    },
    goHome() {
      this.$router.push("/");
    },
    refresh() {
      this.$router.go(0);
    },
    removeAll() {
      this.$refs.pageTab.removeAll();
      this.$router.push("/");
    },
    controlSiderBar() {
      this.openSider = !this.openSider;
      this.$store.commit("setOpenSider", this.openSider);
    },
    getRoleCode(val) {
      this.roleCode = val;
    },
  },
  beforeDestroy() {
    // EventBus.$off("handleCloseTip");
  },
};
</script>
<style lang="less" scoped>
@import url("@/assets/style/public.less");
.sys-right-container {
  background: #f0f2f5;
  height: 100%;
  width: calc(100% - @menuWidth);
  position: relative;
  .sider-bar-control {
    position: absolute;
    left: 0px;
    top: 50%;
    width: 20px;
    height: 80px;
    background: @themColor;
    border-radius: 0 8px 8px 0;
    cursor: pointer;
    i {
      line-height: 80px;
      color: #fff;
      font-size: 20px;
    }
  }
}
.sys-content-container {
  height: 33px;
}
.content-view-container {
  height: calc(100vh - 145px);
  overflow-y: auto;
  margin: 0px 10px 0px 10px;
}
.tab-box {
  background: #fff;
  height: 44px;
  margin-bottom: 10px;
  overflow: hidden;
  border-bottom: 1px solid #e7ecf8;
  .tab-container {
    float: left;
    overflow: hidden;
    width: calc(100% - 71px);
  }
  .right-operation {
    float: right;
    width: 70px;
    margin-top: 10px;
    border-left: 1px solid #dedede;
    text-align: center;
    cursor: pointer;
  }
}
</style>
